package com.wxzz.elearing.comment.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.comment.entity.CommunityComment;
import com.wxzz.elearing.comment.entity.StudyComment;
import com.wxzz.elearing.comment.service.ICommunityGiveLikeService;
import com.wxzz.elearing.comment.service.IStudyGiveLikeService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/wx-study-give-Like-community")
@Api(tags = "学以致用点赞及热度接口(小程序)")
public class WxStudyGiveLikeController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Resource
    private IStudyGiveLikeService iStudyGiveLikeService;

    @ApiOperation(value = "学以致用点赞及热度接口(小程序)", notes = "学以致用点赞及热度接口(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "giveLike", method = RequestMethod.POST)
    public ReturnVO giveLike(@RequestBody StudyComment comment, @RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        comment.setWxUserId(jsonObject.getLong("id"));
//        comment.setWxUserId(1392071664227999745L);
        return iStudyGiveLikeService.giveLike(comment);
    }
}
